<!doctype html>

<html>
<head>
  <link rel="shortcut icon" href="static/images/favicon.ico" type="image/x-icon">
  <title>scrollfloater.js (Closure Library API Documentation - JavaScript)</title>
  <link rel="stylesheet" href="static/css/base.css">
  <link rel="stylesheet" href="static/css/doc.css">
  <link rel="stylesheet" href="static/css/sidetree.css">
  <link rel="stylesheet" href="static/css/prettify.css">

  <script>
     var _staticFilePath = "static/";
     var _typeTreeName = "goog";
     var _fileTreeName = "Source";
  </script>

  <script src="static/js/doc.js">
  </script>


  <meta charset="utf8">
</head>

<body onload="grokdoc.onLoad();">

<div id="header">
  <div class="g-section g-tpl-50-50 g-split">
    <div class="g-unit g-first">
      <a id="logo" href="index.html">Closure Library API Documentation</a>
    </div>

    <div class="g-unit">
      <div class="g-c">
        <strong>Go to class or file:</strong>
        <input type="text" id="ac">
      </div>
    </div>
  </div>
</div>

<div class="clear"></div>

<h2><a href="local_closure_goog_ui_scrollfloater.js.html">scrollfloater.js</a></h2>

<pre class="prettyprint lang-js">
<a name="line1"></a>// Copyright 2008 The Closure Library Authors. All Rights Reserved.
<a name="line2"></a>//
<a name="line3"></a>// Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);
<a name="line4"></a>// you may not use this file except in compliance with the License.
<a name="line5"></a>// You may obtain a copy of the License at
<a name="line6"></a>//
<a name="line7"></a>//      http://www.apache.org/licenses/LICENSE-2.0
<a name="line8"></a>//
<a name="line9"></a>// Unless required by applicable law or agreed to in writing, software
<a name="line10"></a>// distributed under the License is distributed on an &quot;AS-IS&quot; BASIS,
<a name="line11"></a>// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
<a name="line12"></a>// See the License for the specific language governing permissions and
<a name="line13"></a>// limitations under the License.
<a name="line14"></a>
<a name="line15"></a>/**
<a name="line16"></a> * @fileoverview  Class for making an element detach and float to remain visible
<a name="line17"></a> * even when the viewport has been scrolled.
<a name="line18"></a> * &lt;p&gt;
<a name="line19"></a> * The element remains at its normal position in the layout until scrolling
<a name="line20"></a> * would cause its top edge to scroll off the top of the viewport; at that
<a name="line21"></a> * point, the element is replaced with an invisible placeholder (to keep the
<a name="line22"></a> * layout stable), reattached in the dom tree to a new parent (the body element
<a name="line23"></a> * by default), and set to &quot;fixed&quot; positioning (emulated for IE &lt; 7) so that it
<a name="line24"></a> * remains at its original X position while staying fixed to the top of the
<a name="line25"></a> * viewport in the Y dimension.
<a name="line26"></a> * &lt;p&gt;
<a name="line27"></a> * When the window is scrolled up past the point where the original element
<a name="line28"></a> * would be fully visible again, the element snaps back into place, replacing
<a name="line29"></a> * the placeholder.
<a name="line30"></a> *
<a name="line31"></a> * @see ../demos/scrollfloater.html
<a name="line32"></a> *
<a name="line33"></a> * Adapted from http://go/elementfloater.js
<a name="line34"></a> */
<a name="line35"></a>
<a name="line36"></a>
<a name="line37"></a>goog.provide(&#39;goog.ui.ScrollFloater&#39;);
<a name="line38"></a>goog.provide(&#39;goog.ui.ScrollFloater.EventType&#39;);
<a name="line39"></a>
<a name="line40"></a>goog.require(&#39;goog.array&#39;);
<a name="line41"></a>goog.require(&#39;goog.asserts&#39;);
<a name="line42"></a>goog.require(&#39;goog.dom&#39;);
<a name="line43"></a>goog.require(&#39;goog.dom.classlist&#39;);
<a name="line44"></a>goog.require(&#39;goog.events.EventType&#39;);
<a name="line45"></a>goog.require(&#39;goog.style&#39;);
<a name="line46"></a>goog.require(&#39;goog.ui.Component&#39;);
<a name="line47"></a>goog.require(&#39;goog.userAgent&#39;);
<a name="line48"></a>
<a name="line49"></a>
<a name="line50"></a>
<a name="line51"></a>/**
<a name="line52"></a> * Creates a ScrollFloater; see file overview for details.
<a name="line53"></a> *
<a name="line54"></a> * @param {Element=} opt_parentElement Where to attach the element when it&#39;s
<a name="line55"></a> *     floating.  Default is the document body.  If the floating element
<a name="line56"></a> *     contains form inputs, it will be necessary to attach it to the
<a name="line57"></a> *     corresponding form element, or to an element in the DOM subtree under
<a name="line58"></a> *     the form element.
<a name="line59"></a> * @param {goog.dom.DomHelper=} opt_domHelper Optional DOM helper.
<a name="line60"></a> * @constructor
<a name="line61"></a> * @extends {goog.ui.Component}
<a name="line62"></a> */
<a name="line63"></a>goog.ui.ScrollFloater = function(opt_parentElement, opt_domHelper) {
<a name="line64"></a>  // If a parentElement is supplied, we want to use its domHelper,
<a name="line65"></a>  // ignoring the caller-supplied one.
<a name="line66"></a>  var domHelper = opt_parentElement ?
<a name="line67"></a>      goog.dom.getDomHelper(opt_parentElement) : opt_domHelper;
<a name="line68"></a>
<a name="line69"></a>  goog.ui.ScrollFloater.base(this, &#39;constructor&#39;, domHelper);
<a name="line70"></a>
<a name="line71"></a>  /**
<a name="line72"></a>   * The element to which the scroll-floated element will be attached
<a name="line73"></a>   * when it is floating.
<a name="line74"></a>   * @type {Element}
<a name="line75"></a>   * @private
<a name="line76"></a>   */
<a name="line77"></a>  this.parentElement_ =
<a name="line78"></a>      opt_parentElement || this.getDomHelper().getDocument().body;
<a name="line79"></a>
<a name="line80"></a>  /**
<a name="line81"></a>   * The original styles applied to the element before it began floating;
<a name="line82"></a>   * used to restore those styles when the element stops floating.
<a name="line83"></a>   * @type {Object}
<a name="line84"></a>   * @private
<a name="line85"></a>   */
<a name="line86"></a>  this.originalStyles_ = {};
<a name="line87"></a>
<a name="line88"></a>  /**
<a name="line89"></a>   * A vertical offset from which to start floating the element.  This is
<a name="line90"></a>   * useful in cases when there are &#39;position:fixed&#39; elements covering up
<a name="line91"></a>   * part of the viewport.
<a name="line92"></a>   * @type {number}
<a name="line93"></a>   * @private
<a name="line94"></a>   */
<a name="line95"></a>  this.viewportTopOffset_ = 0;
<a name="line96"></a>
<a name="line97"></a>  /**
<a name="line98"></a>   * An element used to define the boundaries within which the floater can
<a name="line99"></a>   * be positioned.
<a name="line100"></a>   * @type {Element}
<a name="line101"></a>   * @private
<a name="line102"></a>   */
<a name="line103"></a>  this.containerElement_ = null;
<a name="line104"></a>
<a name="line105"></a>  /**
<a name="line106"></a>   * Container element&#39;s bounding rectangle.
<a name="line107"></a>   * @type {goog.math.Rect}
<a name="line108"></a>   * @private
<a name="line109"></a>   */
<a name="line110"></a>  this.containerBounds_ = null;
<a name="line111"></a>
<a name="line112"></a>  /**
<a name="line113"></a>   * Element&#39;s original bounding rectangle.
<a name="line114"></a>   * @type {goog.math.Rect}
<a name="line115"></a>   * @private
<a name="line116"></a>   */
<a name="line117"></a>  this.originalBounds_ = null;
<a name="line118"></a>
<a name="line119"></a>  /**
<a name="line120"></a>   * Element&#39;s top offset when it&#39;s not floated or pinned.
<a name="line121"></a>   * @type {number}
<a name="line122"></a>   * @private
<a name="line123"></a>   */
<a name="line124"></a>  this.originalTopOffset_ = 0;
<a name="line125"></a>
<a name="line126"></a>  /**
<a name="line127"></a>   * The placeholder element dropped in to hold the layout for
<a name="line128"></a>   * the floated element.
<a name="line129"></a>   * @type {Element}
<a name="line130"></a>   * @private
<a name="line131"></a>   */
<a name="line132"></a>  this.placeholder_ = null;
<a name="line133"></a>
<a name="line134"></a>  /**
<a name="line135"></a>   * Whether scrolling is enabled for this element; true by default.
<a name="line136"></a>   * The {@link #setScrollingEnabled} method can be used to change this value.
<a name="line137"></a>   * @type {boolean}
<a name="line138"></a>   * @private
<a name="line139"></a>   */
<a name="line140"></a>  this.scrollingEnabled_ = true;
<a name="line141"></a>
<a name="line142"></a>  /**
<a name="line143"></a>   * A flag indicating whether this instance is currently pinned to the bottom
<a name="line144"></a>   * of the container element.
<a name="line145"></a>   * @type {boolean}
<a name="line146"></a>   * @private
<a name="line147"></a>   */
<a name="line148"></a>  this.pinned_ = false;
<a name="line149"></a>
<a name="line150"></a>  /**
<a name="line151"></a>   * A flag indicating whether this instance is currently floating.
<a name="line152"></a>   * @type {boolean}
<a name="line153"></a>   * @private
<a name="line154"></a>   */
<a name="line155"></a>  this.floating_ = false;
<a name="line156"></a>};
<a name="line157"></a>goog.inherits(goog.ui.ScrollFloater, goog.ui.Component);
<a name="line158"></a>
<a name="line159"></a>
<a name="line160"></a>/**
<a name="line161"></a> * Events dispatched by this component.
<a name="line162"></a> * @enum {string}
<a name="line163"></a> */
<a name="line164"></a>goog.ui.ScrollFloater.EventType = {
<a name="line165"></a>  /**
<a name="line166"></a>   * Dispatched when the component starts floating. The event is
<a name="line167"></a>   * cancellable.
<a name="line168"></a>   */
<a name="line169"></a>  FLOAT: &#39;float&#39;,
<a name="line170"></a>
<a name="line171"></a>  /**
<a name="line172"></a>   * Dispatched when the component returns to its original state.
<a name="line173"></a>   * The event is cancellable.
<a name="line174"></a>   */
<a name="line175"></a>  DOCK: &#39;dock&#39;,
<a name="line176"></a>
<a name="line177"></a>  /**
<a name="line178"></a>   * Dispatched when the component gets pinned to the bottom of the
<a name="line179"></a>   * container element.  This event is cancellable.
<a name="line180"></a>   */
<a name="line181"></a>  PIN: &#39;pin&#39;
<a name="line182"></a>};
<a name="line183"></a>
<a name="line184"></a>
<a name="line185"></a>/**
<a name="line186"></a> * The element can float at different positions on the page.
<a name="line187"></a> * @enum {number}
<a name="line188"></a> * @private
<a name="line189"></a> */
<a name="line190"></a>goog.ui.ScrollFloater.FloatMode_ = {
<a name="line191"></a>  TOP: 0,
<a name="line192"></a>  BOTTOM: 1
<a name="line193"></a>};
<a name="line194"></a>
<a name="line195"></a>
<a name="line196"></a>/**
<a name="line197"></a> * The style properties which are stored when we float an element, so they
<a name="line198"></a> * can be restored when it &#39;docks&#39; again.
<a name="line199"></a> * @type {Array.&lt;string&gt;}
<a name="line200"></a> * @private
<a name="line201"></a> */
<a name="line202"></a>goog.ui.ScrollFloater.STORED_STYLE_PROPS_ = [
<a name="line203"></a>  &#39;position&#39;, &#39;top&#39;, &#39;left&#39;, &#39;width&#39;, &#39;cssFloat&#39;];
<a name="line204"></a>
<a name="line205"></a>
<a name="line206"></a>/**
<a name="line207"></a> * The style elements managed for the placeholder object.
<a name="line208"></a> * @type {Array.&lt;string&gt;}
<a name="line209"></a> * @private
<a name="line210"></a> */
<a name="line211"></a>goog.ui.ScrollFloater.PLACEHOLDER_STYLE_PROPS_ = [
<a name="line212"></a>  &#39;position&#39;, &#39;top&#39;, &#39;left&#39;, &#39;display&#39;, &#39;cssFloat&#39;,
<a name="line213"></a>  &#39;marginTop&#39;, &#39;marginLeft&#39;, &#39;marginRight&#39;, &#39;marginBottom&#39;];
<a name="line214"></a>
<a name="line215"></a>
<a name="line216"></a>/**
<a name="line217"></a> * The class name applied to the floating element.
<a name="line218"></a> * @type {string}
<a name="line219"></a> * @private
<a name="line220"></a> */
<a name="line221"></a>goog.ui.ScrollFloater.CSS_CLASS_ = goog.getCssName(&#39;goog-scrollfloater&#39;);
<a name="line222"></a>
<a name="line223"></a>
<a name="line224"></a>/**
<a name="line225"></a> * Delegates dom creation to superclass, then constructs and
<a name="line226"></a> * decorates required DOM elements.
<a name="line227"></a> * @override
<a name="line228"></a> */
<a name="line229"></a>goog.ui.ScrollFloater.prototype.createDom = function() {
<a name="line230"></a>  goog.ui.ScrollFloater.base(this, &#39;createDom&#39;);
<a name="line231"></a>
<a name="line232"></a>  this.decorateInternal(this.getElement());
<a name="line233"></a>};
<a name="line234"></a>
<a name="line235"></a>
<a name="line236"></a>/**
<a name="line237"></a> * Decorates the floated element with the standard ScrollFloater CSS class.
<a name="line238"></a> * @param {Element} element The element to decorate.
<a name="line239"></a> * @override
<a name="line240"></a> */
<a name="line241"></a>goog.ui.ScrollFloater.prototype.decorateInternal = function(element) {
<a name="line242"></a>  goog.ui.ScrollFloater.base(this, &#39;decorateInternal&#39;, element);
<a name="line243"></a>  goog.asserts.assert(element);
<a name="line244"></a>  goog.dom.classlist.add(element, goog.ui.ScrollFloater.CSS_CLASS_);
<a name="line245"></a>};
<a name="line246"></a>
<a name="line247"></a>
<a name="line248"></a>/** @override */
<a name="line249"></a>goog.ui.ScrollFloater.prototype.enterDocument = function() {
<a name="line250"></a>  goog.ui.ScrollFloater.base(this, &#39;enterDocument&#39;);
<a name="line251"></a>
<a name="line252"></a>  if (!this.placeholder_) {
<a name="line253"></a>    this.placeholder_ =
<a name="line254"></a>        this.getDomHelper().createDom(&#39;div&#39;, {&#39;style&#39;: &#39;visibility:hidden&#39;});
<a name="line255"></a>  }
<a name="line256"></a>
<a name="line257"></a>  this.update();
<a name="line258"></a>
<a name="line259"></a>  this.setScrollingEnabled(this.scrollingEnabled_);
<a name="line260"></a>  var win = this.getDomHelper().getWindow();
<a name="line261"></a>  this.getHandler().
<a name="line262"></a>      listen(win, goog.events.EventType.SCROLL, this.handleScroll_).
<a name="line263"></a>      listen(win, goog.events.EventType.RESIZE, this.update);
<a name="line264"></a>};
<a name="line265"></a>
<a name="line266"></a>
<a name="line267"></a>/**
<a name="line268"></a> * Forces the component to update the cached element positions and sizes and
<a name="line269"></a> * to re-evaluate whether the the component should be docked, floated or
<a name="line270"></a> * pinned.
<a name="line271"></a> */
<a name="line272"></a>goog.ui.ScrollFloater.prototype.update = function() {
<a name="line273"></a>  if (!this.isInDocument()) {
<a name="line274"></a>    return;
<a name="line275"></a>  }
<a name="line276"></a>
<a name="line277"></a>  // These values can only be calculated when the element is in its original
<a name="line278"></a>  // state, so we dock first, and then re-evaluate.
<a name="line279"></a>  this.dock_();
<a name="line280"></a>  if (this.containerElement_) {
<a name="line281"></a>    this.containerBounds_ = goog.style.getBounds(this.containerElement_);
<a name="line282"></a>  }
<a name="line283"></a>  this.originalBounds_ = goog.style.getBounds(this.getElement());
<a name="line284"></a>  this.originalTopOffset_ = goog.style.getPageOffset(this.getElement()).y;
<a name="line285"></a>  this.handleScroll_();
<a name="line286"></a>};
<a name="line287"></a>
<a name="line288"></a>
<a name="line289"></a>/** @override */
<a name="line290"></a>goog.ui.ScrollFloater.prototype.disposeInternal = function() {
<a name="line291"></a>  goog.ui.ScrollFloater.base(this, &#39;disposeInternal&#39;);
<a name="line292"></a>
<a name="line293"></a>  this.placeholder_ = null;
<a name="line294"></a>};
<a name="line295"></a>
<a name="line296"></a>
<a name="line297"></a>/**
<a name="line298"></a> * Sets whether the element should be floated if it scrolls out of view.
<a name="line299"></a> * @param {boolean} enable Whether floating is enabled for this element.
<a name="line300"></a> */
<a name="line301"></a>goog.ui.ScrollFloater.prototype.setScrollingEnabled = function(enable) {
<a name="line302"></a>  this.scrollingEnabled_ = enable;
<a name="line303"></a>
<a name="line304"></a>  if (enable) {
<a name="line305"></a>    this.applyIeBgHack_();
<a name="line306"></a>    this.handleScroll_();
<a name="line307"></a>  } else {
<a name="line308"></a>    this.dock_();
<a name="line309"></a>  }
<a name="line310"></a>};
<a name="line311"></a>
<a name="line312"></a>
<a name="line313"></a>/**
<a name="line314"></a> * @return {boolean} Whether the component is enabled for scroll-floating.
<a name="line315"></a> */
<a name="line316"></a>goog.ui.ScrollFloater.prototype.isScrollingEnabled = function() {
<a name="line317"></a>  return this.scrollingEnabled_;
<a name="line318"></a>};
<a name="line319"></a>
<a name="line320"></a>
<a name="line321"></a>/**
<a name="line322"></a> * @return {boolean} Whether the component is currently scroll-floating.
<a name="line323"></a> */
<a name="line324"></a>goog.ui.ScrollFloater.prototype.isFloating = function() {
<a name="line325"></a>  return this.floating_;
<a name="line326"></a>};
<a name="line327"></a>
<a name="line328"></a>
<a name="line329"></a>/**
<a name="line330"></a> * @return {boolean} Whether the component is currently pinned to the bottom
<a name="line331"></a> *     of the container.
<a name="line332"></a> */
<a name="line333"></a>goog.ui.ScrollFloater.prototype.isPinned = function() {
<a name="line334"></a>  return this.pinned_;
<a name="line335"></a>};
<a name="line336"></a>
<a name="line337"></a>
<a name="line338"></a>/**
<a name="line339"></a> * @param {number} offset A vertical offset from the top of the viewport, from
<a name="line340"></a> *    which to start floating the element. Default is 0. This is useful in cases
<a name="line341"></a> *    when there are &#39;position:fixed&#39; elements covering up part of the viewport.
<a name="line342"></a> */
<a name="line343"></a>goog.ui.ScrollFloater.prototype.setViewportTopOffset = function(offset) {
<a name="line344"></a>  this.viewportTopOffset_ = offset;
<a name="line345"></a>  this.update();
<a name="line346"></a>};
<a name="line347"></a>
<a name="line348"></a>
<a name="line349"></a>/**
<a name="line350"></a> * @param {Element} container An element used to define the boundaries within
<a name="line351"></a> *     which the floater can be positioned. If not specified, scrolling the page
<a name="line352"></a> *     down far enough may result in the floated element extending past the
<a name="line353"></a> *     containing element as it is being scrolled out of the viewport. In some
<a name="line354"></a> *     cases, such as a list with a sticky header, this may be undesirable. If
<a name="line355"></a> *     the container element is specified and the floated element extends past
<a name="line356"></a> *     the bottom of the container, the element will be pinned to the bottom of
<a name="line357"></a> *     the container.
<a name="line358"></a> */
<a name="line359"></a>goog.ui.ScrollFloater.prototype.setContainerElement = function(container) {
<a name="line360"></a>  this.containerElement_ = container;
<a name="line361"></a>  this.update();
<a name="line362"></a>};
<a name="line363"></a>
<a name="line364"></a>
<a name="line365"></a>/**
<a name="line366"></a> * When a scroll event occurs, compares the element&#39;s position to the current
<a name="line367"></a> * document scroll position, and stops or starts floating behavior if needed.
<a name="line368"></a> * @param {goog.events.Event=} opt_e The event, which is ignored.
<a name="line369"></a> * @private
<a name="line370"></a> */
<a name="line371"></a>goog.ui.ScrollFloater.prototype.handleScroll_ = function(opt_e) {
<a name="line372"></a>  if (this.scrollingEnabled_) {
<a name="line373"></a>    var scrollTop = this.getDomHelper().getDocumentScroll().y;
<a name="line374"></a>
<a name="line375"></a>    if (this.originalBounds_.top - scrollTop &gt;= this.viewportTopOffset_) {
<a name="line376"></a>      this.dock_();
<a name="line377"></a>      return;
<a name="line378"></a>    }
<a name="line379"></a>
<a name="line380"></a>    var effectiveElementHeight = this.originalBounds_.height +
<a name="line381"></a>        this.viewportTopOffset_;
<a name="line382"></a>
<a name="line383"></a>    // If the element extends past the container, we need to pin it instead.
<a name="line384"></a>    if (this.containerElement_) {
<a name="line385"></a>      var containerBottom = this.containerBounds_.top +
<a name="line386"></a>          this.containerBounds_.height;
<a name="line387"></a>
<a name="line388"></a>      if (scrollTop &gt; containerBottom - effectiveElementHeight) {
<a name="line389"></a>        this.pin_();
<a name="line390"></a>        return;
<a name="line391"></a>      }
<a name="line392"></a>    }
<a name="line393"></a>
<a name="line394"></a>    var windowHeight = this.getDomHelper().getViewportSize().height;
<a name="line395"></a>
<a name="line396"></a>    // If the element is shorter than the window or the user uses IE &lt; 7,
<a name="line397"></a>    // float it at the top.
<a name="line398"></a>    if (this.needsIePositionHack_() || effectiveElementHeight &lt; windowHeight) {
<a name="line399"></a>      this.float_(goog.ui.ScrollFloater.FloatMode_.TOP);
<a name="line400"></a>      return;
<a name="line401"></a>    }
<a name="line402"></a>
<a name="line403"></a>    // If the element is taller than the window and is extending past the
<a name="line404"></a>    // bottom, allow it scroll with the page until the bottom of the element is
<a name="line405"></a>    // fully visible.
<a name="line406"></a>    if (this.originalBounds_.height + this.originalTopOffset_ &gt;
<a name="line407"></a>        windowHeight + scrollTop) {
<a name="line408"></a>      this.dock_();
<a name="line409"></a>    } else {
<a name="line410"></a>      // Pin the element to the bottom of the page since the user has scrolled
<a name="line411"></a>      // past it.
<a name="line412"></a>      this.float_(goog.ui.ScrollFloater.FloatMode_.BOTTOM);
<a name="line413"></a>    }
<a name="line414"></a>  }
<a name="line415"></a>};
<a name="line416"></a>
<a name="line417"></a>
<a name="line418"></a>/**
<a name="line419"></a> * Pins the element to the bottom of the container, making as much of the
<a name="line420"></a> * element visible as possible without extending past it.
<a name="line421"></a> * @private
<a name="line422"></a> */
<a name="line423"></a>goog.ui.ScrollFloater.prototype.pin_ = function() {
<a name="line424"></a>  if (this.floating_ &amp;&amp; !this.dock_()) {
<a name="line425"></a>    return;
<a name="line426"></a>  }
<a name="line427"></a>
<a name="line428"></a>  // Ignore if the component is pinned or the PIN event is cancelled.
<a name="line429"></a>  if (this.pinned_ ||
<a name="line430"></a>      !this.dispatchEvent(goog.ui.ScrollFloater.EventType.PIN)) {
<a name="line431"></a>    return;
<a name="line432"></a>  }
<a name="line433"></a>
<a name="line434"></a>  var elem = this.getElement();
<a name="line435"></a>
<a name="line436"></a>  this.storeOriginalStyles_();
<a name="line437"></a>
<a name="line438"></a>  elem.style.position = &#39;relative&#39;;
<a name="line439"></a>  elem.style.top = this.containerBounds_.height - this.originalBounds_.height -
<a name="line440"></a>      this.originalBounds_.top + this.containerBounds_.top + &#39;px&#39;;
<a name="line441"></a>
<a name="line442"></a>  this.pinned_ = true;
<a name="line443"></a>};
<a name="line444"></a>
<a name="line445"></a>
<a name="line446"></a>/**
<a name="line447"></a> * Begins floating behavior, making the element position:fixed (or IE hacked
<a name="line448"></a> * equivalent) and inserting a placeholder where it used to be to keep the
<a name="line449"></a> * layout from shifting around. For IE &lt; 7 users, we only support floating at
<a name="line450"></a> * the top.
<a name="line451"></a> * @param {goog.ui.ScrollFloater.FloatMode_} floatMode The position at which we
<a name="line452"></a> *     should float.
<a name="line453"></a> * @private
<a name="line454"></a> */
<a name="line455"></a>goog.ui.ScrollFloater.prototype.float_ = function(floatMode) {
<a name="line456"></a>  var isTop = floatMode == goog.ui.ScrollFloater.FloatMode_.TOP;
<a name="line457"></a>  if (this.pinned_ &amp;&amp; !this.dock_()) {
<a name="line458"></a>    return;
<a name="line459"></a>  }
<a name="line460"></a>
<a name="line461"></a>  // Ignore if the component is floating or the FLOAT event is cancelled.
<a name="line462"></a>  if (this.floating_ ||
<a name="line463"></a>      !this.dispatchEvent(goog.ui.ScrollFloater.EventType.FLOAT)) {
<a name="line464"></a>    return;
<a name="line465"></a>  }
<a name="line466"></a>
<a name="line467"></a>  var elem = this.getElement();
<a name="line468"></a>  var doc = this.getDomHelper().getDocument();
<a name="line469"></a>
<a name="line470"></a>  // Read properties of element before modifying it.
<a name="line471"></a>  var originalLeft_ = goog.style.getPageOffsetLeft(elem);
<a name="line472"></a>  var originalWidth_ = goog.style.getContentBoxSize(elem).width;
<a name="line473"></a>
<a name="line474"></a>  this.storeOriginalStyles_();
<a name="line475"></a>
<a name="line476"></a>  goog.style.setSize(this.placeholder_, elem.offsetWidth, elem.offsetHeight);
<a name="line477"></a>
<a name="line478"></a>  // Make element float.
<a name="line479"></a>  goog.style.setStyle(elem, {
<a name="line480"></a>    &#39;left&#39;: originalLeft_ + &#39;px&#39;,
<a name="line481"></a>    &#39;width&#39;: originalWidth_ + &#39;px&#39;,
<a name="line482"></a>    &#39;cssFloat&#39;: &#39;none&#39;
<a name="line483"></a>  });
<a name="line484"></a>
<a name="line485"></a>  // If parents are the same, avoid detaching and reattaching elem.
<a name="line486"></a>  // This prevents Flash embeds from being reloaded, for example.
<a name="line487"></a>  if (elem.parentNode == this.parentElement_) {
<a name="line488"></a>    elem.parentNode.insertBefore(this.placeholder_, elem);
<a name="line489"></a>  } else {
<a name="line490"></a>    elem.parentNode.replaceChild(this.placeholder_, elem);
<a name="line491"></a>    this.parentElement_.appendChild(elem);
<a name="line492"></a>  }
<a name="line493"></a>
<a name="line494"></a>  // Versions of IE below 7-in-standards-mode don&#39;t handle &#39;position: fixed&#39;,
<a name="line495"></a>  // so we must emulate it using an IE-specific idiom for JS-based calculated
<a name="line496"></a>  // style values. These users will only ever float at the top (bottom floating
<a name="line497"></a>  // not supported.) Also checked in handleScroll_.
<a name="line498"></a>  if (this.needsIePositionHack_()) {
<a name="line499"></a>    elem.style.position = &#39;absolute&#39;;
<a name="line500"></a>    elem.style.setExpression(&#39;top&#39;,
<a name="line501"></a>        &#39;document.compatMode==&quot;CSS1Compat&quot;?&#39; +
<a name="line502"></a>        &#39;documentElement.scrollTop:document.body.scrollTop&#39;);
<a name="line503"></a>  } else {
<a name="line504"></a>    elem.style.position = &#39;fixed&#39;;
<a name="line505"></a>    if (isTop) {
<a name="line506"></a>      elem.style.top = this.viewportTopOffset_ + &#39;px&#39;;
<a name="line507"></a>      elem.style.bottom = &#39;auto&#39;;
<a name="line508"></a>    } else {
<a name="line509"></a>      elem.style.top = &#39;auto&#39;;
<a name="line510"></a>      elem.style.bottom = 0;
<a name="line511"></a>    }
<a name="line512"></a>  }
<a name="line513"></a>
<a name="line514"></a>  this.floating_ = true;
<a name="line515"></a>};
<a name="line516"></a>
<a name="line517"></a>
<a name="line518"></a>/**
<a name="line519"></a> * Stops floating behavior, returning element to its original state.
<a name="line520"></a> * @return {boolean} True if the the element has been docked.  False if the
<a name="line521"></a> *     element is already docked or the event was cancelled.
<a name="line522"></a> * @private
<a name="line523"></a> */
<a name="line524"></a>goog.ui.ScrollFloater.prototype.dock_ = function() {
<a name="line525"></a>  // Ignore if the component is docked or the DOCK event is cancelled.
<a name="line526"></a>  if (!(this.floating_ || this.pinned_) ||
<a name="line527"></a>      !this.dispatchEvent(goog.ui.ScrollFloater.EventType.DOCK)) {
<a name="line528"></a>    return false;
<a name="line529"></a>  }
<a name="line530"></a>
<a name="line531"></a>  var elem = this.getElement();
<a name="line532"></a>
<a name="line533"></a>  if (this.floating_) {
<a name="line534"></a>    this.restoreOriginalStyles_();
<a name="line535"></a>
<a name="line536"></a>    if (this.needsIePositionHack_()) {
<a name="line537"></a>      elem.style.removeExpression(&#39;top&#39;);
<a name="line538"></a>    }
<a name="line539"></a>
<a name="line540"></a>    // If placeholder_ was inserted and didn&#39;t replace elem then elem has
<a name="line541"></a>    // the right parent already, no need to replace (which removes elem before
<a name="line542"></a>    // inserting it).
<a name="line543"></a>    if (this.placeholder_.parentNode == this.parentElement_) {
<a name="line544"></a>      this.placeholder_.parentNode.removeChild(this.placeholder_);
<a name="line545"></a>    } else {
<a name="line546"></a>      this.placeholder_.parentNode.replaceChild(elem, this.placeholder_);
<a name="line547"></a>    }
<a name="line548"></a>  }
<a name="line549"></a>
<a name="line550"></a>  if (this.pinned_) {
<a name="line551"></a>    this.restoreOriginalStyles_();
<a name="line552"></a>  }
<a name="line553"></a>
<a name="line554"></a>  this.floating_ = this.pinned_ = false;
<a name="line555"></a>
<a name="line556"></a>  return true;
<a name="line557"></a>};
<a name="line558"></a>
<a name="line559"></a>
<a name="line560"></a>/**
<a name="line561"></a> * @private
<a name="line562"></a> */
<a name="line563"></a>goog.ui.ScrollFloater.prototype.storeOriginalStyles_ = function() {
<a name="line564"></a>  var elem = this.getElement();
<a name="line565"></a>  this.originalStyles_ = {};
<a name="line566"></a>
<a name="line567"></a>  // Store styles while not floating so we can restore them when the
<a name="line568"></a>  // element stops floating.
<a name="line569"></a>  goog.array.forEach(goog.ui.ScrollFloater.STORED_STYLE_PROPS_,
<a name="line570"></a>                     function(property) {
<a name="line571"></a>                       this.originalStyles_[property] = elem.style[property];
<a name="line572"></a>                     },
<a name="line573"></a>                     this);
<a name="line574"></a>
<a name="line575"></a>  // Copy relevant styles to placeholder so it will be layed out the same
<a name="line576"></a>  // as the element that&#39;s about to be floated.
<a name="line577"></a>  goog.array.forEach(goog.ui.ScrollFloater.PLACEHOLDER_STYLE_PROPS_,
<a name="line578"></a>                     function(property) {
<a name="line579"></a>                       this.placeholder_.style[property] =
<a name="line580"></a>                           elem.style[property] ||
<a name="line581"></a>                               goog.style.getCascadedStyle(elem, property) ||
<a name="line582"></a>                               goog.style.getComputedStyle(elem, property);
<a name="line583"></a>                     },
<a name="line584"></a>                     this);
<a name="line585"></a>};
<a name="line586"></a>
<a name="line587"></a>
<a name="line588"></a>/**
<a name="line589"></a> * @private
<a name="line590"></a> */
<a name="line591"></a>goog.ui.ScrollFloater.prototype.restoreOriginalStyles_ = function() {
<a name="line592"></a>  var elem = this.getElement();
<a name="line593"></a>  for (var prop in this.originalStyles_) {
<a name="line594"></a>    elem.style[prop] = this.originalStyles_[prop];
<a name="line595"></a>  }
<a name="line596"></a>};
<a name="line597"></a>
<a name="line598"></a>
<a name="line599"></a>/**
<a name="line600"></a> * Determines whether we need to apply the position hack to emulated position:
<a name="line601"></a> * fixed on this browser.
<a name="line602"></a> * @return {boolean} Whether the current browser needs the position hack.
<a name="line603"></a> * @private
<a name="line604"></a> */
<a name="line605"></a>goog.ui.ScrollFloater.prototype.needsIePositionHack_ = function() {
<a name="line606"></a>  return goog.userAgent.IE &amp;&amp;
<a name="line607"></a>      !(goog.userAgent.isVersionOrHigher(&#39;7&#39;) &amp;&amp;
<a name="line608"></a>          this.getDomHelper().isCss1CompatMode());
<a name="line609"></a>};
<a name="line610"></a>
<a name="line611"></a>
<a name="line612"></a>/**
<a name="line613"></a> * Sets some magic CSS properties that make float-scrolling work smoothly
<a name="line614"></a> * in IE6 (and IE7 in quirks mode). Without this hack, the floating element
<a name="line615"></a> * will appear jumpy when you scroll the document. This involves modifying
<a name="line616"></a> * the background of the HTML element (or BODY in quirks mode). If there&#39;s
<a name="line617"></a> * already a background image in use this is not required.
<a name="line618"></a> * For further reading, see
<a name="line619"></a> * http://annevankesteren.nl/2005/01/position-fixed-in-ie
<a name="line620"></a> * @private
<a name="line621"></a> */
<a name="line622"></a>goog.ui.ScrollFloater.prototype.applyIeBgHack_ = function() {
<a name="line623"></a>  if (this.needsIePositionHack_()) {
<a name="line624"></a>    var doc = this.getDomHelper().getDocument();
<a name="line625"></a>    var topLevelElement = goog.style.getClientViewportElement(doc);
<a name="line626"></a>
<a name="line627"></a>    if (topLevelElement.currentStyle.backgroundImage == &#39;none&#39;) {
<a name="line628"></a>      // Using an https URL if the current windowbp is https avoids an IE
<a name="line629"></a>      // &quot;This page contains a mix of secure and nonsecure items&quot; warning.
<a name="line630"></a>      topLevelElement.style.backgroundImage =
<a name="line631"></a>          this.getDomHelper().getWindow().location.protocol == &#39;https:&#39; ?
<a name="line632"></a>              &#39;url(https:///)&#39; : &#39;url(about:blank)&#39;;
<a name="line633"></a>      topLevelElement.style.backgroundAttachment = &#39;fixed&#39;;
<a name="line634"></a>    }
<a name="line635"></a>  }
<a name="line636"></a>};
</pre>


</body>
</html>
